package com.yida.gwj.report.service.impl;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yida.common.core.utils.PageUtils;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.common.constant.GwjConstants;
import com.yida.gwj.report.domain.dto.GwjNoticeItemDTO;
import com.yida.gwj.report.mapper.GwjHomeNoticeMapper;
import com.yida.gwj.report.service.IGwjHomeNoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: PPV
 * @Date: 2023-03-06
 */
@Service
public class GwjHomeNoticeServiceImpl implements IGwjHomeNoticeService {

    @Resource
    private GwjHomeNoticeMapper noticeMapper;

    //间隔日常量
    private static final int INTERVAL = 7;

    @Override
    public TableDataInfo getTodoTable(Long areaId) {
        List<GwjNoticeItemDTO> todoList = noticeMapper.getNoticeList(getParamMap(GwjConstants.NO, areaId));
        return PageUtils.getDataTable(todoList);
    }

    @Override
    public TableDataInfo getDoneTable(Long areaId) {
        List<GwjNoticeItemDTO> doneList = noticeMapper.getNoticeList(getParamMap(GwjConstants.YES, areaId));
        return PageUtils.getDataTable(doneList);
    }

    @Override
    public TableDataInfo getWarmingTable(Long areaId) {
        List<GwjNoticeItemDTO> warmingList = noticeMapper.getWarmingList(getParamMap(null, areaId));
        return PageUtils.getDataTable(warmingList);
    }

    @Override
    public TableDataInfo getUnCollectedList(Long areaId) {
        List<GwjNoticeItemDTO> unCollectedList = noticeMapper.getUnCollectedList(getParamMap(null, areaId));
        return PageUtils.getDataTable(unCollectedList);
    }

    /**
     * 查询参数构造
     *
     * @param status 事项状态
     * @param areaId 地区ID
     * @return
     */
    private Map<String, Object> getParamMap(String status, Long areaId) {
        PageUtils.startPage();
        Map<String, Object> paramMap = MapBuilder.<String, Object>create().put("userId", SecurityUtils.getUserId()).put("interval", INTERVAL).build();

        if (ObjectUtil.isEmpty(areaId)) {
            paramMap.put("areaId", SecurityUtils.getAreaId());
        } else {
            paramMap.put("areaId", areaId);
        }

        if (StrUtil.isNotBlank(status)) {
            paramMap.put("isDone", status);
        }

        return paramMap;
    }




}
